#!/bin/bash
# 获取系统信息、编程语言版本及运行环境

echo "=== 系统版本信息 ==="
# 系统发行版检测（兼容RedHat/Debian系）
if [ -f /etc/os-release ]; then
    echo "[系统名称]"
    grep -E '^NAME=|^PRETTY_NAME=' /etc/os-release | cut -d '"' -f2
    echo "[内核版本] $(uname -r)"
elif [ -f /etc/redhat-release ]; then
    echo "[系统版本] $(cat /etc/redhat-release)"
else
    echo "[警告] 无法识别系统类型"
fi

echo -e "\n=== 编程语言版本 ==="
# 检查常用语言环境
check_tool() {
    if command -v $1 &>/dev/null; then
        echo "[$1] $($2)"
    else
        echo "[$1] 未安装"
    fi
}

check_tool "Python" "python3 --version 2>&1 | awk '{print \$2}'"
check_tool "Node.js" "node --version | cut -d 'v' -f2"
check_tool "Java" "java -version 2>&1 | head -n1 | awk '{print \$3}' | tr -d '\"'"
check_tool "GCC" "gcc --version | head -n1 | awk '{print \$4}'"
check_tool "Ruby" "ruby --version | awk '{print \$2}'"
check_tool "PHP" "php --version | head -n1 | awk '{print \$2}'"
check_tool "Go" "go version | awk '{print \$3}' | cut -d 'o' -f2"

echo -e "\n=== 运行环境信息 ==="
echo "[主机名] $(hostname)"
echo "[当前用户] $(whoami)"
echo "[运行时间] $(uptime -p | sed 's/up //')"
echo "[环境变量PATH] $PATH"

# 检测虚拟化环境（物理机/虚拟机）
if [ $(systemd-detect-virt) = "none" ]; then
    echo "[虚拟化] 物理机"
else
    echo "[虚拟化] $(systemd-detect-virt)"
fi